﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using SharpMap.Forms;
using SharpMap.Layers;

namespace SharpMapApp
{
    public partial class MainForm : Form
    {
        private LayerForm m_layerForm;
        private MapForm m_mapForm;

        public MainForm()
        {
            InitializeComponent();

            m_mapForm = new MapForm();
            m_layerForm = new LayerForm(m_mapForm.MapImage);

            m_layerForm.Show(dockPanel, DockState.DockLeft);
            m_mapForm.Show(dockPanel, DockState.Document);

        }

        /// <summary>
        /// 新建地图
        /// </summary>
        private void NewMap()
        {
            MessageBox.Show("功能未实现");
        }
        /// <summary>
        /// 载入地图
        /// </summary>
        private void LoadLayer()
        {
            DialogResult result = AddLayerDialog.ShowDialog(this);

            if (result == DialogResult.OK)
            {
                m_layerForm.AddLayer(AddLayerDialog.FileNames);
                ZoomToExtends();
            }
        }
        /// <summary>
        /// 改变地图操作模式
        /// </summary>
        private void ChangeMapMode(MapImage.Tools tool)
        {
            m_mapForm.MapImage.ActiveTool = tool;

            ZoomInToolStripButton.Checked = (tool == MapImage.Tools.ZoomIn);
            ZoomOutToolStripButton.Checked = (tool == MapImage.Tools.ZoomOut);
            PanToolStripButton.Checked = (tool == MapImage.Tools.Pan);
            //toolStripButtonZoomIn.Checked = (tool == MapImage.Tools.Query);
        }
        /// <summary>
        /// 全屏显示地图
        /// </summary>
        private void ZoomToExtends()
        {
            if (m_mapForm.MapImage.Map.Layers.Count < 1) return;
            m_mapForm.MapImage.Map.ZoomToExtents();
            m_mapForm.MapImage.Refresh();
        }

        #region 菜单 工具栏事件
        /// <summary>
        /// 新建
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void NewToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 打开
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LoadLayer();
        }
        /// <summary>
        /// 退出
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 图层视图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LayerToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 地图视图
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void MapToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
        /// <summary>
        /// 漫游
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void PanToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BeginInvoke((MethodInvoker)delegate { ChangeMapMode(MapImage.Tools.Pan); });
        }
        /// <summary>
        /// 放大
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ZoomInToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BeginInvoke((MethodInvoker)delegate { ChangeMapMode(MapImage.Tools.ZoomIn); });
        }
        /// <summary>
        /// 缩小
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ZoomOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            BeginInvoke((MethodInvoker)delegate { ChangeMapMode(MapImage.Tools.ZoomOut); });
        }
        /// <summary>
        /// 全屏显示
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ZoomExtendsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ZoomToExtends();
        }
        #endregion
    }
}
